Repository navigation
docs: explain how to collect coverage from web workers - #1012
Merged
Merged
Conversation
The support hooks read `__coverage__` from the app and spec windows only. An instrumented dedicated worker keeps its counters on its own global, so its code never reached the report. Document a workaround: the worker replies to a coverage request over a MessageChannel, and an afterEach hook in the support file sends each reply to the combineCoverage task. Refs #102 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WUv8r3qbyBkGWEnvGWtCrX
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WUv8r3qbyBkGWEnvGWtCrX
Soften the lead-in to the workaround's limits, drop a step count that didn't match the list, and nest the code samples under their steps so the numbered list renders as one list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WUv8r3qbyBkGWEnvGWtCrX
|
🎉 This PR is included in version 4.1.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Additional details
Why does code running in a Web Worker never show up in the report? The support hooks only read
__coverage__from the app window and the spec window (lib/support.ts). An instrumented worker keeps its counters on its own global,self.__coverage__, so the plugin never sees them.This PR doesn't change any code. It adds a Coverage from web workers section to
README.md, right after the backend coverage docs, with a workaround people can copy:self.__coverage__inside the worker to confirm it.messagelistener sendsself.__coverage__back over aMessageChannelport, so the app's own main-threadmessagehandlers never see the reply.win.Workerinwindow:before:loadto keep track of each worker. After each test, ask every worker for its coverage, with a 1-second timeout for workers that won't answer, and send each reply to the existingcombineCoveragetask.A first-class API (for example, a
collectCoverage()command) could come later, but it's out of scope here.Steps to test
coverage/with the expected hit counts.What I verified:
npm run build,npm test(30 passed) andnpm run format:checkpass.nullinstead of hanging, and the app's main-thread handler only saw its own message.npm run check:markdowncouldn't reach outside hosts from my environment, so every GitHub link failed on master too, and so did the two new MDN links. CI will give the real result.How has the user experience changed?
No change to how the plugin behaves. The README gains a new section on collecting coverage from web workers.
Generated by Claude Code
Note
Low Risk
Documentation-only change with no runtime or plugin behavior changes.
Overview
Adds a Coverage from web workers section to
README.md(after the backend coverage docs) explaining why worker code is absent from reports and how to merge it manually.The new text states that the plugin only reads
window.__coverage__from app and spec windows, while instrumented workers keep counters onself.__coverage__. It documents a copy-paste workaround: instrument the worker bundle, respond to acypress:coveragemessage over aMessageChannel, tracknew Worker()instances from the Cypress support file, collect coverage inafterEach, and forward each payload to the existingcombineCoveragetask.It also calls out limits—coverage must be collected before the worker ends, each worker is polled once per test, and dedicated workers only (not shared or service workers).
Reviewed by Cursor Bugbot for commit e56f413. Bugbot is set up for automated code reviews on this repo. Configure here.